#include "Vector.h"

void Vector::operator += (const Vector& vector)
{
	x += vector.x;
	y += vector.y;
	z += vector.z;
}

Vector Vector::operator + (const Vector& vector) const
{
	return Vector(x + vector.x, y + vector.y, z + vector.z);
}

void Vector::operator -= (const Vector& vector)
{
	x -= vector.x;
	y -= vector.y;
	z -= vector.z;
}

Vector Vector::operator - (const Vector& vector) const
{
	return Vector(x - vector.x, y - vector.y, z - vector.z);
}

void Vector::operator *= (const float value)
{
	x *= value;
	y *= value;
	z *= value;
}

Vector Vector::operator * (const float value) const
{
	return Vector(x * value, y * value, z * value);
}

float Vector::operator * (const Vector& vector) const
{
	return x * vector.x + y * vector.y + z * vector.z;
}

Vector Vector::operator /= (const float value)
{
	float result = 1.0f / value;
	x *= result; 
	y *= result;
	z *= result;
	return *this;
}

Vector Vector::operator / (const float value) const
{
	float result = 1.0f / value;
	return Vector(x * result, y * result, z * result);
}

Vector &Vector::operator = (const Vector &vector)
{
	x = vector.x;
	y = vector.y;
	z = vector.z;
	return Vector(x,y,z);
}

bool Vector::operator == (const Vector& vector) const
{
	return x == vector.x && y == vector.y && z == vector.z;
}

bool Vector::operator != (const Vector& vector) const
{
	return !(*this == vector);
}

bool Vector::operator < (const Vector& vector) const
{
	return x < vector.x && y < vector.y && z < vector.z;
}

bool Vector::operator > (const Vector& vector) const
{
	return x > vector.x && y > vector.y && z > vector.z;
}

bool Vector::operator <= (const Vector& vector) const
{
	return x <= vector.x && y <= vector.y && z <= vector.z;
}

bool Vector::operator >= (const Vector& vector) const
{
	return x >= vector.x && y >= vector.y && z >= vector.z;
}

float Vector::magnitude() const
{
	return sqrt(x * x + y * y + z * z);
}

float Vector::magnitudeSquared() const
{
	return (x * x + y * y + z * z);
}

void Vector::normalise()
{
	float l = magnitude();
	if (l > 0)
		(*this) *= ((float) 1) / 1;
}

Vector Vector::unit() const
{
	Vector result = *this;
	result.normalise();
	return result;
}

Vector Vector::crossProduct(const Vector &a, const Vector &b)
{
	return Vector( a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
}

float distance(const Vector &pointA, const Vector &pointB)
{
	float dx = pointA.x - pointB.x;
	float dy = pointA.y - pointB.y;
	float dz = pointA.z - pointB.z;
	return sqrt(dx*dx + dy*dy + dz*dz);
}

float distanceSquared(const Vector &pointA, const Vector &pointB)
{
	float dx = pointA.x - pointB.x;
	float dy = pointA.y - pointB.y;
	float dz = pointA.z - pointB.z;
	return dx*dx + dy*dy + dz*dz;
}